/*
 * @Descripttion: 
 * @version: 
 * @Author: yuanliutech
 * @Date: 2023-01-05 17:01:05
 * @LastEditors: yuanliutech@lwj
 * @LastEditTime: 2023-02-20 14:48:45
 */
const app = getApp()
const exitLoginBehavior = require('../../behaviors/personal/exitLogin.js')
import {
    showMsg
} from '../../../utils/config.js'
import {
    reqOrgApprovalAdd
} from '../../../request/api'
Page({
    behaviors: [exitLoginBehavior],
    data: {
        disabledBtn: false,
        username: ''
    },
    usernameChange(e) {
        this.setData({
            username: e.detail.value
        })
    },
    clearUsername() {
        this.setData({
            username: ''
        })
    },
    async confirm() {
        if (this.data.disabledBtn) return
        let {
            username
        } = this.data
        if (!username) return showMsg("请输入团队编号")
        let params = {
            orgCode: username,
            userId: app.globalData.userId
        }
        const res = await reqOrgApprovalAdd(params)
        if (res.code === 12007) {
            showMsg(res.message)
            // setTimeout(() => {
            //     this.exitLogin()
            // }, 1000)
            return
        }
        if (res.code != 20000) return showMsg(res.message)
        // showMsg("加入成功", "success")
        showMsg("已提出申请，等待管理员审核")
        this.setData({
            disabledBtn: true
        })
        
        // setTimeout(() => {
        //     this.exitLogin()
        // }, 1000)
    }
})